﻿using Abp.Configuration.Startup;
using Abp.Modules;
using Abp.Reflection.Extensions;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Yoyo.Learn.Configuration;
using Yoyo.Learn.Web.Portal.Startup.Navigation;

namespace Yoyo.Learn.Web.Portal.Startup
{
    [DependsOn(typeof(LearnWebCoreModule))]
    public class LearnWebPortalModule:AbpModule
    {
    


        private readonly IHostingEnvironment _env;
        private readonly IConfigurationRoot _appConfiguration;

        public LearnWebPortalModule(IHostingEnvironment env)
        {
            _env = env;
            _appConfiguration = env.GetAppConfiguration();
        }


        public override void PreInitialize()
        {


            Configuration.Modules.AbpWebCommon().MultiTenancy.DomainFormat =
                _appConfiguration["App:WebSiteClientRootAddress"] ?? "http://localhost:7123/";



            //Changed AntiForgery token/cookie names to not conflict to the main application while redirections.
            Configuration.Modules.AbpWebCommon().AntiForgery.TokenCookieName = "Portal-XSRF-TOKEN";
            Configuration.Modules.AbpWebCommon().AntiForgery.TokenHeaderName = "Portal-X-XSRF-TOKEN";



            //关闭后台作业job，默认是关闭。

            Configuration.BackgroundJobs.IsJobExecutionEnabled = false;

            // 补充导航
           Configuration.Navigation.Providers.Add<PortalNavigationProvider>();

          //如果是开发环境

          if (_env.IsDevelopment())
          {//则打印所有错误信息到门户端
              Configuration.Modules.AbpWebCommon().SendAllExceptionsToClients = true;
          }

          

 
        }


        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(typeof(LearnWebPortalModule).GetAssembly());
        }

    }
}
